package com.zhou.config;

import com.ibeetl.starter.BeetlTemplateCustomize;
import com.zaxxer.hikari.HikariDataSource;
import org.beetl.core.GroupTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import javax.sql.DataSource;

/**
 * HikariCP 数据库配置
 */
@Configuration
public class DataSourceConfig {

    @Bean(name = " dataSource ")
    // Environment 类在 Spring Boot 中代表了环境上下 文 ，包含了 application . propertie s 配置属性、 JVM 系统属性和操作系统环境变量的类
    public DataSource datasource(Environment env) {
        HikariDataSource ds = new HikariDataSource();
        ds.setJdbcUrl(env.getProperty("spring.datasource.url"));
        ds.setUsername(env.getProperty("spring.datasource.username"));
        ds.setPassword(env.getProperty("spring.datasource.password"));
        ds.setDriverClassName(env.getProperty("spring.datasource.driver-class-name"));
        return ds;
    }

    @Bean
    public BeetlTemplateCustomize beetlTemplateCustomize() {
        return new BeetlTemplateCustomize() {
            public void customize(GroupTemplate groupTemplate) {

            }
        };
    }
}
